package single.shop.web.service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import single.shop.common.util.BrandDOToBrandVo;
import single.shop.search.client.BrandSearchFacade;
import single.shop.search.model.bean.BrandDO;
import single.shop.web.common.form.QueryForm;
import single.shop.web.controller.IndexController;

/**
 *	首页业务
 *
 */
@Service  
public class IndexService {   
	
	private static final Log LOG = LogFactory.getLog(IndexController.class);
	private static final int PageSize = 120;
    
	@Resource
	ThreadPoolTaskExecutor threadPoolTaskExecutor;
    
	@Autowired
	BrandSearchFacade brandSearchFacade;
	/**
	 * 获得首页商品
	 * @param modelMap
	 * @param queryForm
	 * 1、获得分区信
	 * 2、获得商品id列表
	 * 3、批量得到商品基本信
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public ModelMap handler(HttpServletRequest request,ModelMap modelMap,QueryForm queryForm) throws Exception{
		long k = System.currentTimeMillis();
		int id = queryForm.getId();
		if (id == 0) {
			id = 1;
		}
		BrandDO brandDO = brandSearchFacade.getBrandDoById(id);
		modelMap.put("brand", new BrandDOToBrandVo().handler(brandDO));
		
		/******加载异步加载的数据结束*****/
		LOG.info("首页Service执行总时间为（ms）："+(System.currentTimeMillis() - k));
		return modelMap;
	}

	@SuppressWarnings("unchecked")
	public ModelMap modify(HttpServletRequest request,ModelMap modelMap,QueryForm queryForm) throws Exception{
		long k = System.currentTimeMillis();
		int id = queryForm.getId();
		if (id == 0) {
			id = 1;
		}
		BrandDO brandDO = brandSearchFacade.getBrandDoById(id);
		modelMap.put("brand", new BrandDOToBrandVo().handler(brandDO));
		
		/******加载异步加载的数据结束*****/
		LOG.info("首页Service执行总时间为（ms）："+(System.currentTimeMillis() - k));
		return modelMap;
	}

	
}
